﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// Poker Card 类型定义
namespace PP.PPPoker
{
    // Card 牌值
    public enum CardValue
    {
        _2 = 2,
        _3 = 3,
        _4 = 4,
        _5 = 5,
        _6 = 6,
        _7 = 7,
        _8 = 8,
        _9 = 9,
        _10 = 10,
        J = 11,
        Q = 12,
        K = 13,
        A = 14
    }

    public static class CardValueExtension
    {
        public static string ToValueString(this CardValue cardValue)
        {
            return cardValue.ToString().Replace("_", "");
        }

        public static string ToValueUpperString(this CardValue cardValue)
        {
            return cardValue.ToValueString();
        }

        public static string ToValueLowerString(this CardValue cardValue)
        {
            return cardValue.ToValueString().ToLower();
        }
    }

    // Card 花色
    public enum CardFullSuit
    {
        Diamonds = 1,
        Clubs = 2,
        Hearts = 3,
        Spades = 4,
    }

    // Card 花色 简洁类型
    public enum CardShortSuit
    {
        d = 1,
        c = 2,
        h = 3,
        s = 4,
    }

    /// <summary>
    /// CardCode 数值类型
    /// </summary>
    public static class CardCode
    {

        public static int MakeCardCode(CardFullSuit cardSuit, CardValue cardValue)
        {
            return (int)cardSuit * 256 + (int)cardValue;
        }

        public static int MakeCardCode(CardShortSuit cardSuit, CardValue cardValue)
        {
            return (int)cardSuit * 256 + (int)cardValue;
        }

        /// <summary>
        /// 点数.数值 (2/3...14)
        /// </summary>
        public static int GetCardValue(this int cardCode)
        {
            int value = cardCode % 256;
            return value;
        }


        /// <summary>
        /// 点数.枚举类型 ( CardValue._2, CardValue.A)
        /// </summary>
        public static CardValue GetCardValueType(this int cardCode)
        {
            int value = cardCode % 256;
            return (CardValue)value;
        }

        /// <summary>
        /// 点数.小写字符 （2/3...j/q/k/a）
        /// </summary>
        public static string GetCardValueLowerStr(this int cardCode)
        {
            var cardValue = cardCode.GetCardValueType();
            return cardValue.ToValueLowerString();
        }




        /// <summary>
        /// 花色值 (1/2/3/4)
        /// </summary>
        public static int GetCardSuit(this int cardCode)
        {
            int suit = cardCode / 256;
            return suit;
        }

        /// <summary>
        /// 花色字符 (d/c/h/s)
        /// </summary>
        public static string GetCardColor(this int cardCode)
        {
            return cardCode.GetCardShortSuitType().ToString();
        }

        /// <summary>
        /// 花色枚举类型 (CardShortSuit.d,..)
        /// </summary>
        public static CardShortSuit GetCardShortSuitType(this int cardCode)
        {
            int suit = cardCode / 256;
            return (CardShortSuit)suit;
        }


        /// <summary>
        /// 花色枚举类型 (CardFullSuit.Diamonds,..)
        /// </summary>
        public static CardFullSuit GetCardFullSuitType(this int cardCode)
        {
            int suit = cardCode / 256;
            return (CardFullSuit)suit;
        }




 

        public static string DisplayCardCode(this int cardCode)
        {
            return $"{cardCode.GetCardValueLowerStr()}{cardCode.GetCardColor()}";
        }
    }
}
